package com.antoco.controlcenter.utils;

import android.text.TextUtils;

public class TimeUtil {

    public static String startTime(String time, int step) {
        time = TextUtils.isEmpty(time) ? "00:00:00" : time;
        int hh = 0;
        int mm = 0;
        int ss = 0;

        String[] timeStrs = time.split(":");
        int length = timeStrs.length;
        if (length >= 1) {
            hh = getTimeValue(timeStrs[0]);
        }
        if (length >= 2) {
            mm = getTimeValue(timeStrs[1]);
        }
        if (length >= 3) {
            ss = getTimeValue(timeStrs[2]);
        }
        ss += step;
        if (ss >= 60) {
            ss = 0;
            mm += 1;
        }

        if (mm >= 60) {
            hh += 1;
            mm = 0;
        }

        String ssShow = String.valueOf(ss);
        if (ssShow.length() <= 1) {
            ssShow = "0" + ssShow;
        }
        String mmShow = String.valueOf(mm);
        if (mmShow.length() <= 1) {
            mmShow = "0" + mmShow;
        }
        String hhShow = String.valueOf(hh);
        if (hhShow.length() <= 1) {
            hhShow = "0" + mmShow;
        }
        time = hhShow + ":" + mmShow + ":" + ssShow;
        return time;
    }

    private static int getTimeValue(String str) {
        int time = 0;
        if (0 != Integer.parseInt(String.valueOf(str.charAt(0)))) {
            time = Integer.parseInt(str);
        } else {
            time = Integer.parseInt(String.valueOf(str.charAt(1)));
        }
        return time;
    }
}
